
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 这样才能使用Vue -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>   
</head>
<body>
    
    <style>
        .red{
            background-color: red;
        }
        .yellow{
            background-color: yellow;
        }
        .green{
            background-color: green;
        }
        .image{
            width: 500px;
            height: 400px;
            border:10px solid red;
        }
        .box{
            width: 100px;
            height: 100px;
        }
        
    </style>

    <div id="app">

        <button @click="showOnHidden">{{ showBtnText }}</button>
        <div class="box red" v-show='show'></div>
        <div class="box yellow" v-show='show'></div>

        <button @click="handleClick">点击</button>
        <h4 :class="backColors[styleIndex]">{{ name }}</h4>
        <img class="image" :src="imgUrl" :alt="name">
    </div>

    <script>
       const vm = new Vue({
            el:'#app',
            data:{
                showBtnText:'隐藏',
                show:true,
                name:'11111',
                backColors:['red', 'yellow', 'green'],
                styleIndex:0,
                imgUrl:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1571815385879&di=1d93c97f21d37691e76f2436c94a7c5e&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fimage%2Fpic%2Fitem%2F4610b912c8fcc3cef70d70409845d688d53f20f7.jpg'
            },
            methods:{
                // 隐藏或显示
                showOnHidden(){
                    this.show = !this.show;
                    if (this.show == true) {
                        this.showBtnText='隐藏';
                    } else {
                        this.showBtnText='显示';
                    }
                },
                // 改变背景色
                handleClick(){
                    if (this.styleIndex == 2) {
                        this.styleIndex = 0;
                    } else {
                        this.styleIndex += 1;
                    }
                }
            }
        })
        console.log(vm.$data.name);
    </script>

</body>
</html>